package com.loser.gateway.cmd.after.Impl;

import cn.hutool.core.convert.Convert;
import com.loser.gateway.cmd.after.CmdAfterHandler;
import com.loser.gateway.utils.ChannelUtils;
import com.loser.module.base.proto.base.InnerRequest;
import com.loser.module.base.proto.sdk.cmd.modul.UserCmd;
import com.loser.module.base.proto.sdk.user.request.UserLogOutReq;
import com.loser.module.base.proto.sdk.user.request.UserLoginReq;
import com.loser.utils.SerializationUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class LoginCmdHandler implements CmdAfterHandler {

    @Override
    public int getCmd() {
        return UserCmd.loginCmd;
    }

    @Override
    public void process(ChannelHandlerContext ctx, InnerRequest req) {

        ChannelUtils.addChannel(ctx.channel());
        UserLoginReq loginReq = SerializationUtil.deserializeFromByte(req.getBytes(), UserLoginReq.class);
        ChannelUtils.addChannelUserId(ctx.channel(), Convert.toStr(loginReq.getUserId()));

    }

}
